#include <Wire.h>

#define SCL  5 //GLB_GPIO_PIN_15 //0
#define SDA  4 //GLB_GPIO_PIN_14 //1

void setup() {
  Serial.begin(9600);
  //Wire.setSCL(U8G2_SCL);
  //Wire.setSDA(U8G2_SDA);
  //Wire.begin(U8G2_SDA, U8G2_SCL); // 使用D1引脚作为SDA，D2引脚作为SCL
  Wire.begin(SDA,SCL);
  Serial.println("\nI2C Scanner");

  // 打印表头
  Serial.println(" 0 1 2 3 4 5 6 7 8 9 A B C D E F");

  // 扫描I2C地址
  for (byte address = 1; address < 127; ++address) {
    Wire.beginTransmission(address);
    byte error = Wire.endTransmission();

    if (error == 0) {
      Serial.print("v");                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
    } else if (error == 4) {
      Serial.print("?");
    } else {
      Serial.print("!");
    }

    Serial.print("  ");
    if (address < 16) {
      Serial.print("0");
    }
    Serial.print(address, HEX);

    if ((address + 1) % 16 == 0) {
      Serial.println();
    }
  }
  Serial.println("\nI2C 地址扫描结束");
}

void loop() {}